package com.copro.chemdb.stat;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.ihelpuoo.lang.NumericUtils;

import com.copro.simple.Application;

public class DisplayStatChartAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int subjectId = NumericUtils.parseInt(request.getParameter("id"), -1);
		Application app = Application.me(request);
		byte[] b = app.getStatChart(subjectId);
		if (b == null || b.length == 0) {
			String path = request.getSession().getServletContext().getRealPath(
					"/images/unknowpic.gif");
			File f = new File(path);
			InputStream is = new FileInputStream(f);
			b = new byte[is.available()];
			is.read(b, 0, b.length);
		}
		response.getOutputStream().write(b);
		return null;
	}

}
